 <?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

if ($is_dhtml_editor) {
    include_once("$g4[path]/lib/cheditor4.lib.php");
    echo "<script src='$g4[cheditor4_path]/cheditor.js'></script>";
    echo cheditor1('wr_content', '100%', '250');
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$g4['charset']?>" />
<title>집구하기</title>
<link rel="stylesheet" type="text/css" href="../css/home.css">
<link rel="stylesheet" type="text/css" href="../css/reset.css">
<script type="text/javascript" src="<?=$g4['path']?>/js/money.js"></script>
<script type="text/javascript">
// 글자수 제한
var char_min = parseInt(<?=$write_min?>); // 최소
var char_max = parseInt(<?=$write_max?>); // 최대

$(document).ready(function(){
	if ($("#chkMore").attr("checked")){
		$("#divMoreD1").show();
	}else{
		$("#divMoreD1").hide();
	}

	//금액을 문자로
	NUM_HAN($("#homePrice").val(),3,$('#EMONEY_HAN'));
	$("#homePrice").val(numchk($("#homePrice").val()));
});

//스트립트 추가
function goFocus(obj){
	switch(obj.name){
	case "wr_3":
		if (obj.value == "크기")
			obj.value='';
		break;
	case "homePrice":
		if (obj.value == "가격")
			obj.value='';
		break;
	case "wr_4":
		if (obj.value == "입주가능일")
			obj.value='';
		break;
	}
}
function goBlur(obj){
	if (obj.value==""){
		switch(obj.name){
		case "wr_3":
			obj.value='크기';
			break;
		case "homePrice":
			obj.value='가격';
			break;
		case "wr_4":
			obj.value='입주가능일';
			break;
		}
	}
}

function goChkMore(obj){
	//거래구분에 따라 추가입력이 바뀜
	if ($("#wr_1").val()=="D2" || $("#wr_1").val()=="D3"){
		$("#divMoreD2").show();
	}else if ($("#wr_1").val()=="D1"){
		$("#divMoreD2").hide();
	}else{
		$("#chkMore").attr("checked","");
		$("#divMoreD1").hide();
		alert ("거래구분을 먼저 입력하십시오.");
		return;
	}
	
	if (obj.checked){
		$("#divMoreD1").show();
		$("#chkMore").val("1");
	}else{
		$("#divMoreD1").hide();
		$("#chkMore").val("0");
	}
}
</script>
</head>
<body>

<div id="wrap">
	<div id="contents">
	<!-- contents -->
		<h1><a href="/"><img src="../img/comm/logo.gif" /></a></h1>
		<div class="map">
			<img src="../img/home/map.gif" />
		</div>
		<div class="icon001">
			<img src="../img/home/map_icon01.gif" />
			<img src="../img/home/map_icon02.gif" />
			<img src="../img/home/map_icon03.gif" />
		</div>
	<!-- /contents -->
	</div>
	<div id="aside">
	<!-- aside -->
		<div class="top_menu">
			<a href="/"><img src="../img/comm/smenu_home.gif" /></a>
			<img src="../img/comm/smenu_line.gif" />
			<a href="<?=$g4['path']?>/bbs/board_sellitem.php?bo_table=sellitem"><img src="../img/comm/smenu_buy01.gif" /></a>
			<img src="../img/comm/smenu_line.gif" />
			<a href="<?=$g4['path']?>/bbs/board_sellhome.php?bo_table=sellhome"><img src="../img/comm/smenu_home02.gif" /></a>
			<img src="../img/comm/smenu_line.gif" />
			<a href="#"><img src="../img/comm/smenu_job.gif" /></a>
		</div>
		<div class="user_info">
			<?=outlogin("basic2"); // 외부 로그인 ?>
		</div>
		<div class="icon_write"></div>
<form name="fwrite" method="post" onsubmit="return fwrite_submit(this);" enctype="multipart/form-data" style="margin:0px;">
<input type=hidden name=null> 
<input type=hidden name=w        value="<?=$w?>">
<input type=hidden name=bo_table value="<?=$bo_table?>">
<input type=hidden name=wr_id    value="<?=$wr_id?>">
<input type=hidden name=sca      value="<?=$sca?>">
<input type=hidden name=sfl      value="<?=$sfl?>">
<input type=hidden name=stx      value="<?=$stx?>">
<input type=hidden name=spt      value="<?=$spt?>">
<input type=hidden name=sst      value="<?=$sst?>">
<input type=hidden name=sod      value="<?=$sod?>">
<input type=hidden name=page     value="<?=$page?>">

<input type="hidden" name="wr_subject" value="제목없음" />
		<div>
			<input type="radio" name="chkItem" value="sell" <?if($chkItem!="buy"){echo "checked";}?> <?if($w!="")echo "disabled";?>> 판매
			<input type="radio" name="chkItem" value="buy" <?if($chkItem=="buy"){echo "checked";}?> <?if($w!="")echo "disabled";?>> 구매
			<select id="wr_1" name="wr_1" required>
				<option value="">거래구분</option>
				<option value="D1" <?=($write['wr_1']=='D1')?'selected':'';?>>월세</option>
				<option value="D2" <?=($write['wr_1']=='D2')?'selected':'';?>>전세</option>
				<option value="D3" <?=($write['wr_1']=='D3')?'selected':'';?>>매매</option>
			</select>
			<div style="overflow:hidden;margin:5px 0;">
				<select id="wr_2" name="wr_2" required>
					<option value="">주거형태</option>
					<option value="L1" <?=($write['wr_2']=='L1')?'selected':'';?>>원룸</option>
					<option value="L2" <?=($write['wr_2']=='L2')?'selected':'';?>>오피스텔</option>
				</select>
				<input type="text" id="wr_3" name="wr_3" style="width:70px;" onfocus="javascript:goFocus(this);"; onblur="javascript:goBlur(this);" value="<?if($write['wr_3']!="")echo $write['wr_3'];else echo "크기";?>"/>
				<input type="text" id="homePrice" name="homePrice" style="width:70px;" onkeypress="NUM_HAN(this.value,3,$('#EMONEY_HAN'))" onkeyup="this.value=numchk(this.value);NUM_HAN(this.value,3,$('#EMONEY_HAN'))" onfocus="javascript:goFocus(this);"; onblur="javascript:goBlur(this);" value="<?if($write['homePrice']!="")echo $write['homePrice'];else echo "가격";?>"/>
				<input type="hidden" name="EMONEY_HAN" id="EMONEY_HAN" readonly style="border:0;" size="60" />
				<input type="text" id="wr_4" name="wr_4" style="width:70px;"  onfocus="javascript:goFocus(this);"; onblur="javascript:goBlur(this);" value="<?if($write['wr_4']!="")echo $write['wr_4'];else echo "입주가능일";?>"/>
			</div>
			<table width="100%" style="margin-bottom:10px;">
				<tr>
					<td style='padding:5 0 5 0;' colspan="4">
				    	<table width="330" border="0" cellspacing="0" cellpadding="0">
				            <tr>
				                <td height="25"><input class=ed type=text name='mb_zip1' size=4 maxlength=3 readonly required itemname='우편번호 앞자리' value='<?=$write[mb_zip1]?>'>
				                     - 
				                    <input class=ed type=text name='mb_zip2' size=4 maxlength=3 readonly required itemname='우편번호 뒷자리' value='<?=$write[mb_zip2]?>'>
				                    &nbsp;<a href="javascript:;" onclick="win_zip('fwrite', 'mb_zip1', 'mb_zip2', 'mb_addr1', 'mb_addr2');"><img width="91" height="20" src="<?=$member_skin_path?>/skin/member/basic2/img/post_search_btn.gif" border=0 align=absmiddle></a></td>
				            </tr>
				            <tr>
				                <td height="25" colspan="2"><input class=ed type=text name='mb_addr1' size=60 style="width:300px;" readonly required itemname='주소' value='<?=$write[mb_addr1]?>'></td>
				            </tr>
				            <tr>
				                <td height="25" colspan="2"><input class=ed type=text name='mb_addr2' size=60 style="width:300px;" required itemname='상세주소' value='<?=$write[mb_addr2]?>'></td>
				            </tr>
				        </table>
					</td>
				</tr>
			</table>
			<table width="100%" style="margin-bottom:10px;">
				<tr>
					<td><strong>연락처</strong></td>
					<td>: 010.3456.7890 <img src="../img/product/bt_modify.gif" style="vertical-align:middle;" /></td>
					<td align="right" style="padding-bottom:3px;"><img src="../img/home/bt_subway.gif" style="vertical-align:middle;" /></td>
				</tr>
				<tr>
					<td><strong>이메일</strong></td>
					<td>: marketseoul@naver.com <img src="../img/product/bt_modify.gif" style="vertical-align:middle;" /></td>
					<td align="right"><img src="../img/home/bt_university.gif" style="vertical-align:middle;" /></td>
				</tr>
			</table>
			<table width="100%" style="margin-bottom:10px;">
				<tr>
				    <td style='padding:5 0 5 0;' colspan="4">
				        <? if ($is_dhtml_editor) { ?>
				            <?=cheditor2('wr_content', $content);?>
				        <? } else { ?>
				        <table width=100% cellpadding=0 cellspacing=0>
				        <tr height="20px;">
				            <td width=50% align=left valign=bottom>
				                <span style="cursor: pointer;" onclick="textarea_decrease('wr_content', 10);"><img src="<?=$board_skin_path?>/img/up.gif"></span>
				                <span style="cursor: pointer;" onclick="textarea_original('wr_content', 10);"><img src="<?=$board_skin_path?>/img/start.gif"></span>
				                <span style="cursor: pointer;" onclick="textarea_increase('wr_content', 10);"><img src="<?=$board_skin_path?>/img/down.gif"></span></td>
				            <td width=50% align=right><? if ($write_min || $write_max) { ?><span id=char_count></span>글자<?}?></td>
				        </tr>
				        </table>
				        <textarea id="wr_content" name="wr_content" class=tx style='width:100%; word-break:break-all;' rows=10 itemname="내용" required 
				        <? if ($write_min || $write_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"<?}?>><?=$content?></textarea>
				        <? if ($write_min || $write_max) { ?><script type="text/javascript"> check_byte('wr_content', 'char_count'); </script><?}?>
				        <? } ?>
				    </td>
				</tr>
			</table>
<? if ($is_file) { ?>
			<div class="picup">
				<p style="margin-bottom:5px;">
					<img src="../img/home/bt_photo.gif" style="vertical-align:middle;" />
					<span onclick="add_file();" style="cursor:pointer;"><img src="<?=$board_skin_path?>/img/btn_file_add.gif"></span> 
					<span onclick="del_file();" style="cursor:pointer;"><img src="<?=$board_skin_path?>/img/btn_file_minus.gif"></span>
				</p>
				<table id="variableFiles" cellpadding=0 cellspacing=0></table><?// print_r2($file); ?>
<script type="text/javascript">
        var flen = 0;
        function add_file(delete_code)
        {
            var upload_count = <?=(int)$board[bo_upload_count]?>;
            if (upload_count && flen >= upload_count)
            {
                alert("사진은 "+upload_count+"개 까지만 파일 업로드가 가능합니다.");
                return;
            }

            var objTbl;
            var objRow;
            var objCell;
            if (document.getElementById)
                objTbl = document.getElementById("variableFiles");
            else
                objTbl = document.all["variableFiles"];

            objRow = objTbl.insertRow(objTbl.rows.length);
            objCell = objRow.insertCell(0);

            objCell.innerHTML = "<input type='file' class='ed' name='bf_file[]' style=\"width:300px;margin-top:5px;\" title='파일 용량 <?=$upload_max_filesize?> 이하만 업로드 가능'>";
            if (delete_code)
                objCell.innerHTML += delete_code;
            else
            {
                <? if ($is_file_content) { ?>
                objCell.innerHTML += "<br><input type='text' class='ed' size=50 style=\"width:300px;margin-top:5px;\" name='bf_content[]' title='업로드 이미지 파일에 해당 되는 내용을 입력하세요.'>";
                <? } ?>
                ;
            }

            flen++;
        }

        <?=$file_script; //수정시에 필요한 스크립트?>

        function del_file()
        {
            // file_length 이하로는 필드가 삭제되지 않아야 합니다.
            var file_length = <?=(int)$file_length?>;
            var objTbl = document.getElementById("variableFiles");
            if (objTbl.rows.length - 1 > file_length)
            {
                objTbl.deleteRow(objTbl.rows.length - 1);
                flen--;
            }
        }
</script>
				<p style="text-align:center;margin-top:10px;margin-bottom:10px;">
				<input type="checkbox" id="chkMore" name="chkMore" class="chkOption" onclick="javascript:goChkMore(this);" <?=$write['chkMore']=='1'?"checked":"";?> /> 추가입력
				</p>
			</div>
<? } ?>
		<div id="divMoreD1" style="display:none">
			<div class="table09" >
				<table width="100%">
					<tr>
						<th>방수</th>
						<td><input type="text" id="d1_11" name="d1_11" value="<?=$write['d1_11']?>" style="width:80px;" /> 개</td>
						<th>주차공간</th>
						<td>
							<input type="radio" id="d1_12" name="d1_12" value="Y" <?=$write['d1_12']=='Y'?"checked":"";?> /> 유
   							<input type="radio" id="d1_12" name="d1_12" value="N" <?=$write['d1_12']=='N'?"checked":"";?> /> 무
   						</td>
					</tr>
					<tr>
						<th>관리비</th>
						<td colspan="3">
							<input type="text" id="d1_13" name="d1_13" value="<?=$write['d1_13']?>"  style="width:80px;" /> 만원
						</td>
						
					</tr>
				</table>
			</div>
			<div class="option">
				<table width="100%">
					<tr>
						<td rowspan="3" valign="top">옵션</td>
						<td><input type="checkbox" class="chkOption" id="d1_01" name="d1_01" <?=$write['d1_01']=='1'?"checked":"";?> />침대</td>
						<td><input type="checkbox" class="chkOption" id="d1_02" name="d1_02" <?=$write['d1_02']=='1'?"checked":"";?> />냉장고</td>
						<td><input type="checkbox" class="chkOption" id="d1_03" name="d1_03" <?=$write['d1_03']=='1'?"checked":"";?> />세탁기</td>
						<td><input type="checkbox" class="chkOption" id="d1_04" name="d1_04" <?=$write['d1_04']=='1'?"checked":"";?> />에어컨</td>
					</tr>
					<tr>
						<td><input type="checkbox" class="chkOption" id="d1_05" name="d1_05" <?=$write['d1_05']=='1'?"checked":"";?> />옷장</td>
						<td><input type="checkbox" class="chkOption" id="d1_06" name="d1_06" <?=$write['d1_06']=='1'?"checked":"";?> />책상</td>
						<td><input type="checkbox" class="chkOption" id="d1_07" name="d1_07" <?=$write['d1_07']=='1'?"checked":"";?> />전자렌지</td>
						<td><input type="checkbox" class="chkOption" id="d1_08" name="d1_08" <?=$write['d1_08']=='1'?"checked":"";?> />TV</td>
					</tr>
					<tr>
						<td colspan="4"><input type="checkbox" class="chkOption" id="d1_09" name="d1_09" <?=$write['d1_09']=='1'?"checked":"";?> />기타 <input type="text" id="d1_10" name="d1_10" value="<?=$write['d1_10']?>" /></td>
					</tr>
<? if ($is_guest) { ?>
<tr>
    <td class=write_head><img id='kcaptcha_image' /></td>
    <td><input class='ed' type=input size=10 name=wr_key itemname="자동등록방지" required>&nbsp;&nbsp;왼쪽의 글자를 입력하세요.</td>
</tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>
				</table>
			</div>
		</div>
		<div class="sbtn">
			<input type=image id="btn_submit" src="../img/home/bt_upload.gif"  border=0 accesskey='s' style="vertical-align:middle;">
		</div>
		<div>&nbsp;</div>
	<!-- //aside -->
	</div>
</form>
<script type="text/javascript">
<?
// 관리자라면 분류 선택에 '공지' 옵션을 추가함
if ($is_admin) 
{
    /*echo "
    if (typeof(document.fwrite.ca_name) != 'undefined')
    {
        document.fwrite.ca_name.options.length += 1;
        document.fwrite.ca_name.options[document.fwrite.ca_name.options.length-1].value = '공지';
        document.fwrite.ca_name.options[document.fwrite.ca_name.options.length-1].text = '공지';
    }";*/
} 
?>

with (document.fwrite) 
{
    if (typeof(wr_name) != "undefined")
        wr_name.focus();
    /*else if (typeof(wr_subject) != "undefined")
        wr_subject.focus();*/
    else if (typeof(wr_content) != "undefined")
        wr_content.focus();

    if (typeof(ca_name) != "undefined")
        if (w.value == "u")
            ca_name.value = "<?=$write[ca_name]?>";
}

function html_auto_br(obj) 
{
    if (obj.checked) {
        result = confirm("자동 줄바꿈을 하시겠습니까?\n\n자동 줄바꿈은 게시물 내용중 줄바뀐 곳을<br>태그로 변환하는 기능입니다.");
        if (result)
            obj.value = "html2";
        else
            obj.value = "html1";
    }
    else
        obj.value = "";
}

function fwrite_submit(f) 
{
    /*
    var s = "";
    if (s = word_filter_check(f.wr_subject.value)) {
        alert("제목에 금지단어('"+s+"')가 포함되어있습니다");
        return false;
    }

    if (s = word_filter_check(f.wr_content.value)) {
        alert("내용에 금지단어('"+s+"')가 포함되어있습니다");
        return false;
    }
    */

    if (document.getElementById('char_count')) {
        if (char_min > 0 || char_max > 0) {
            var cnt = parseInt(document.getElementById('char_count').innerHTML);
            if (char_min > 0 && char_min > cnt) {
                alert("내용은 "+char_min+"글자 이상 쓰셔야 합니다.");
                return false;
            } 
            else if (char_max > 0 && char_max < cnt) {
                alert("내용은 "+char_max+"글자 이하로 쓰셔야 합니다.");
                return false;
            }
        }
    }

    <?
    if ($is_dhtml_editor) echo cheditor3('wr_content');
    ?>

    if (document.getElementById('tx_wr_content')) {
        if (!ed_wr_content.outputBodyText()) { 
            alert('내용을 입력하십시오.'); 
            ed_wr_content.returnFalse();
            return false;
        }
    }

    var subject = "";
    var content = "";
    $.ajax({
        url: "<?=$board_skin_path?>/ajax.filter.php",
        type: "POST",
        data: {
            "subject": f.wr_subject.value,
            "content": f.wr_content.value
        },
        dataType: "json",
        async: false,
        cache: false,
        success: function(data, textStatus) {
            subject = data.subject;
            content = data.content;
        }
    });

    if (subject) {
        alert("제목에 금지단어('"+subject+"')가 포함되어있습니다");
        f.wr_subject.focus();
        return false;
    }

    if (content) {
        alert("내용에 금지단어('"+content+"')가 포함되어있습니다");
        if (typeof(ed_wr_content) != "undefined") 
            ed_wr_content.returnFalse();
        else 
            f.wr_content.focus();
        return false;
    }

    

    //if (!check_kcaptcha(f.wr_key)) {
        //return false;
    //}

    $(".chkOption").each(function(){
		if ($(this).attr("checked")){
			$(this).val("1");
		}else{
			$(this).val("0");
		}
	});

    document.getElementById('btn_submit').disabled = true;
    //document.getElementById('btn_list').disabled = true;

    <?
    if ($g4[https_url])
        echo "f.action = '$g4[https_url]/$g4[bbs]/write_".$bo_table."_update.php';";
    else
        echo "f.action = './write_".$bo_table."_update.php';";
    ?>
    
    return true;
}
</script>
</div>
</body>
</html>

